import 'package:flutter/material.dart';
import 'package:home/entity/device_entity.dart';
import 'package:home/net/network.dart';
import 'package:home/utils/loger.dart';

class HomePage extends StatefulWidget {
  const HomePage({Key? key}) : super(key: key);

  @override
  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {

  @override
  void initState() {
    super.initState();
    getDevices();
  }

  ///下拉刷新 请求数据
  refresh(){
    getDevices();
  }

  getDevices() async {
    NetWork.getInstance().get<List<StationDevice>>("/devices").then((value){
        if(value.data?.isNotEmpty??false){
          logger.info(value.data);
        }
    });
  }



  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        backgroundColor: Theme.of(context).scaffoldBackgroundColor,
        leading: IconButton(
          color: Theme.of(context).iconTheme.color,
          icon: Icon(Icons.coronavirus ),
          onPressed: (){},
        ),
        actions: [
          IconButton(
            color: Theme.of(context).iconTheme.color,
            icon: Icon(Icons.add),
            onPressed: (){},
          ),
        ],
      ),
      body: RefreshIndicator(
          child: GridView.custom(
              gridDelegate:SliverGridDelegateWithFixedCrossAxisCount(crossAxisCount: 2,),
              childrenDelegate: SliverChildBuilderDelegate((context,index){
                return Text("设备");
              })
          ),
          onRefresh: () async {
              refresh();
          }),
    );
  }
}
